import './Header.css';
import PubSub from 'pubsub-js';
import React from 'react';

export default function Header() {
  function addHandel(e) {
    let value = e.target.value.trim();
    if (value === '') return;
    if (e.key !== 'Enter') return;
    PubSub.publish('add', value);
    e.target.value = '';
  }
  return (
    <div className="todo-header">
      <input type="text" onKeyDown={addHandel} />
    </div>
  );
}
